package com.glsc.ngateway.platform.service;

import com.glsc.ngateway.common.api.common.dto.PageDataResult;
import com.glsc.ngateway.common.api.flowable.dto.demand.FlowableAppendDto;
import com.glsc.ngateway.common.api.flowable.dto.demand.FlowableAssigneeDto;
import com.glsc.ngateway.common.api.flowable.dto.demand.FlowableDemandDto;
import com.glsc.ngateway.common.api.flowable.dto.demand.node.ProcessNode;
import com.glsc.ngateway.common.api.flowable.dto.param.ParamCommentDto;
import com.glsc.ngateway.common.api.flowable.feign.IFeignFlowableService;
import com.glsc.ngateway.common.api.flowable.resp.FlowableResponse;
import com.glsc.ngateway.common.api.flowable.resp.ResponseCommentDto;
import com.glsc.ngateway.common.api.flowable.resp.ResponseSituationDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class CommonService {

    Logger logger = LoggerFactory.getLogger(CommonService.class);

    /**
     * 重名文件重命名
     *
     * @param fileName
     * @param documentInfoList
     * @param i
     * @return
     */
    public String reNameFileName(String fileName, List<FlowableAppendDto> documentInfoList, int i) {
        int index = 0;
        for (int j = 0; j < documentInfoList.size(); j++) {
            if (documentInfoList.get(j).getAppendixName().equals(fileName)) {
                if (j != i) {
                    index++;
                } else {
                    //为了防止文件名称带.
                    int lastIndex = fileName.lastIndexOf(".");
                    if (index != 0) {
                        return fileName.substring(0, lastIndex) + "（" + index + "）" + fileName.substring(lastIndex);
                    } else {
                        return fileName;
                    }
                }
            }
        }
        return fileName;
    }
}
